﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class TheLoaiDAO
    {
        public List<TheLoaiDTO> LayDanhSachTheLoai()
        {
            List<TheLoaiDTO> list = new List<TheLoaiDTO>();
            try
            {
                QLTVEntities contex = new QLTVEntities();
                var query = from theloai in contex.THE_LOAIList
                            select theloai;
                foreach (var theloaiEF in query)
                {
                    TheLoaiDTO theloaiDTO = new TheLoaiDTO();
                    theloaiDTO.MaTheLoai = theloaiEF.MaTheLoai;
                    theloaiDTO.TenTheLoai = theloaiEF.TenTheLoai;
                    list.Add(theloaiDTO);
                }
            }
            catch (System.Exception)
            {
            }
            return list;
        }

        public void ThemTheLoai(TheLoaiDTO theloaiDTO)
        {
            try
            {
                QLTVEntities contex = new QLTVEntities();
                THE_LOAI theloaiEF = new THE_LOAI();
                theloaiEF.TenTheLoai = theloaiDTO.TenTheLoai;
                contex.AddToTHE_LOAIList(theloaiEF);
                contex.SaveChanges();
            }
            catch (System.Exception)
            {
            }
        }
    }
}
